//
//  MyBillForDayVC.m
//  SelfDrivingTravelling-IOS
//
//  Created by Teplot_01 on 16/8/30.
//  Copyright © 2016年 Teplot_01. All rights reserved.
//

#import "MyBillForDayVC.h"
#import "MyBillDetailVC.h"
@interface MyBillForDayVC ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation MyBillForDayVC
{
    UITableView *_tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = superBackgroundColor;
    self.title = @"活动账单";
    [self initTableView];
    //设置多余的分割线不显示
    _tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
    
}
- (void)initTableView{
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(10, 10, KScreenWidth - 20, KScreenHeight - 10)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = superBackgroundColor;
    _tableView.clipsToBounds = NO;
    _tableView.layer.shadowColor = [UIColor grayColor].CGColor;
    _tableView.layer.shadowOffset = CGSizeMake(2,2);//shadowOffset阴影偏移,x向右偏移4，y向下偏移4，默认(0, -3),这个跟shadowRadius配合使用
    _tableView.layer.shadowOpacity = 0.5;
    _tableView.layer.shadowRadius = 2;
    [self.view addSubview:_tableView];
}
#pragma - mark UITableView delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dayArr.count+1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 35;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc]init];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.row == 0) {
        UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth-20, 35)];
        customView.backgroundColor = Theme_Color;
        customView.layer.shadowColor = [UIColor grayColor].CGColor;
        customView.layer.shadowOffset = CGSizeMake(2,2);//shadowOffset阴影偏移,x向右偏移4，y向下偏移4，默认(0, -3),这个跟shadowRadius配合使用
        customView.layer.shadowOpacity = 0.5;
        customView.layer.shadowRadius = 2;
        UILabel *timeLb = [[UILabel alloc]initWithFrame:CGRectMake(8, 0, 100, 35)];
        timeLb.text = self.activityName;
        timeLb.textColor = White_Color;
        timeLb.font = [UIFont systemFontOfSize:15];
        [customView addSubview:timeLb];
        UILabel *totalLb = [[UILabel alloc]initWithFrame:CGRectMake(KScreenWidth - 210, 0, 180, 35)];
        NSString *total = [NSString stringWithFormat:@"%@%@%@",@"目前活动总费用：", self.totalMoney,@"元"];
        totalLb.text = total;
        totalLb.textColor = White_Color;
        totalLb.textAlignment = NSTextAlignmentRight;
        totalLb.font = [UIFont systemFontOfSize:13];
        [customView addSubview:totalLb];
        if (self.dayArr.count == 0) {
            [SVProgressHUD showImage:nil status:@"此活动暂无账单记录"];
        }
        [cell.contentView addSubview:customView];
    }else{
        UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(18, 7, 20, 20)];
        imageV.image = [UIImage imageNamed:@"sun"];
        [cell.contentView addSubview:imageV];
        UILabel *dayLb = [[UILabel alloc]initWithFrame:CGRectMake(40, 0, 100, 35)];
        dayLb.text = self.dayArr[indexPath.row-1][@"payTime"];
        dayLb.font = [UIFont systemFontOfSize:14];
        [cell.contentView addSubview:dayLb];
        UILabel *daySpendLb = [[UILabel alloc]initWithFrame:CGRectMake(KScreenWidth-150, 0, 100, 35)];
        NSString *dayTotal = [NSString stringWithFormat:@"%@%@", self.dayArr[indexPath.row-1][@"money"],@"元"];
        daySpendLb.text = dayTotal;
        daySpendLb.font = [UIFont systemFontOfSize:14];
        daySpendLb.textAlignment = NSTextAlignmentRight;
        [cell.contentView addSubview:daySpendLb];
        UIImageView *triangleImaV = [[UIImageView alloc]initWithFrame:CGRectMake(KScreenWidth-45, 12, 5, 10)];
        triangleImaV.image = [UIImage imageNamed:@"nextnew"];
        [cell.contentView addSubview:triangleImaV];
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row>0) {
        MyBillDetailVC *vc = [[MyBillDetailVC alloc]init];
        vc.dayMoney = self.dayArr[indexPath.row-1][@"money"];
        vc.time = self.dayArr[indexPath.row-1][@"payTime"];
        vc.activityName = self.activityName;
        vc.dayDetailArr = self.dayArr[indexPath.row-1][@"billList"];
        [self.navigationController pushViewController:vc animated:YES];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
